//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.tencent.bugly.crashreport.crash;

import android.content.Context;
import android.os.Build.VERSION;
import com.tencent.bugly.crashreport.common.info.AppInfo;
import com.tencent.bugly.crashreport.common.strategy.StrategyBean;
import com.tencent.bugly.crashreport.common.strategy.a;
import com.tencent.bugly.crashreport.crash.jni.NativeCrashHandler;
import com.tencent.bugly.proguard.o;
import com.tencent.bugly.proguard.p;
import com.tencent.bugly.proguard.r;
import com.tencent.bugly.proguard.u;
import com.tencent.bugly.proguard.w;
import com.tencent.bugly.proguard.x;
import com.tencent.bugly.proguard.z;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public final class c {
    public static int a = 0;
    public static boolean b = false;
    private final Context q;
    public static int c = 2;
    public static boolean d = true;
    public static int e = 20480;
    public static int f = 20480;
    public static long g = 604800000L;
    public static String h = null;
    public static boolean i = false;
    public static String j = null;
    public static int k = 5000;
    public static boolean l = true;
    public static boolean m = false;
    public static String n = null;
    public static String o = null;
    private static c r;
    public final b p;
    private final e s;
    private final NativeCrashHandler t;
    private a u;
    private w v;
    private final com.tencent.bugly.crashreport.crash.anr.b w;
    private Boolean x;
    private int y = 31;
    private boolean z = false;

    private c(int var1, Context var2, w var3, boolean var4, com.tencent.bugly.BuglyStrategy.a var5, o var6, String var7) {
        a = var1;
        var2 = com.tencent.bugly.proguard.z.a(var2);
        this.q = var2;
        this.u = com.tencent.bugly.crashreport.common.strategy.a.a();
        this.v = var3;
        u var8 = com.tencent.bugly.proguard.u.a();
        p var9 = com.tencent.bugly.proguard.p.a();
        this.p = new b(var1, var2, var8, var9, this.u, var5, var6);
        com.tencent.bugly.crashreport.common.info.a var10 = com.tencent.bugly.crashreport.common.info.a.a(var2);
        this.s = new e(var2, this.p, this.u, var10);
        this.t = NativeCrashHandler.getInstance(var2, var10, this.p, this.u, var3, var4, var7);
        var10.F = this.t;
        this.w = new com.tencent.bugly.crashreport.crash.anr.b(var2, this.u, var10, var3, this.p);
    }

    public static synchronized c a(int var0, Context var1, boolean var2, com.tencent.bugly.BuglyStrategy.a var3, o var4, String var5) {
        if (r == null) {
            r = new c(1004, var1, com.tencent.bugly.proguard.w.a(), var2, var3, (o)null, (String)null);
        }

        return r;
    }

    public static synchronized c a() {
        return r;
    }

    public final void a(StrategyBean var1) {
        this.s.a(var1);
        this.t.onStrategyChanged(var1);
        this.w.c();
        long var3 = 3000L;
        com.tencent.bugly.proguard.w.a().a(new NamelessClass_1(), var3);
    }

    public final boolean b() {
        Boolean var1;
        if ((var1 = this.x) != null) {
            return var1;
        } else {
            String var5 = com.tencent.bugly.crashreport.common.info.a.b().d;
            List var2 = com.tencent.bugly.proguard.p.a().a(1);
            ArrayList var3 = new ArrayList();
            if (var2 != null && var2.size() > 0) {
                Iterator var6 = var2.iterator();

                while(var6.hasNext()) {
                    r var4 = (r)var6.next();
                    if (var5.equals(var4.c)) {
                        this.x = true;
                        var3.add(var4);
                    }
                }

                if (var3.size() > 0) {
                    com.tencent.bugly.proguard.p.a().a(var3);
                }

                return true;
            } else {
                this.x = false;
                return false;
            }
        }
    }

    public final synchronized void c() {
        this.s.a();
        this.t.setUserOpened(true);
        if (VERSION.SDK_INT <= 19) {
            this.w.a(true);
        } else {
            this.w.d();
        }
    }

    public final synchronized void d() {
        this.s.b();
        this.t.setUserOpened(false);
        if (VERSION.SDK_INT < 19) {
            this.w.a(false);
        } else {
            this.w.e();
        }
    }

    public final void e() {
        this.s.a();
    }

    public final void f() {
        this.t.setUserOpened(false);
    }

    public final void g() {
        this.t.setUserOpened(true);
    }

    public final void h() {
        if (VERSION.SDK_INT <= 19) {
            this.w.a(true);
        } else {
            this.w.d();
        }
    }

    public final void i() {
        if (VERSION.SDK_INT < 19) {
            this.w.a(false);
        } else {
            this.w.e();
        }
    }

    public final synchronized void a(boolean var1, boolean var2, boolean var3) {
        this.t.testNativeCrash(var1, var2, var3);
    }

    public final synchronized void j() {
        com.tencent.bugly.crashreport.crash.anr.b var10000 = this.w;

        try {
            int var1 = 0;

            while(var1++ < 30) {
                com.tencent.bugly.proguard.x.a("try main sleep for make a test anr! try:%d/30 , kill it if you don't want to wait!", var1);
                com.tencent.bugly.proguard.z.b(5000L);
            }

        } catch (Throwable var2) {
            if (!com.tencent.bugly.proguard.x.a(var2)) {
                var2.printStackTrace();
            }

        }
    }

    public final boolean k() {
        return this.w.a();
    }

    public final void a(final Thread var1, final Throwable var2, boolean var3, String var4, final byte[] var5, final boolean var6) {
        this.v.a(new Runnable() {
            public final void run() {
                try {
                    com.tencent.bugly.proguard.x.c("post a throwable %b", var2);
                    c.this.s.a(var1, var2, false, null, var5);
                    if (var6) {
                        com.tencent.bugly.proguard.x.a("clear user datas");
                        com.tencent.bugly.crashreport.common.info.a.a(c.this.q).C();
                    }

                } catch (Throwable var2x) {
                    if (!com.tencent.bugly.proguard.x.b(var2x)) {
                        var2x.printStackTrace();
                    }

                    com.tencent.bugly.proguard.x.e("java catch error: %s", var2.toString());
                }
            }
        });
    }

    public final void a(CrashDetailBean var1) {
        this.p.e(var1);
    }

    public final void a(long var1) {
        com.tencent.bugly.proguard.w.a().a(new NamelessClass_1(), var1);
    }

    class NamelessClass_1 extends Thread {
        public final void run() {
            if (com.tencent.bugly.proguard.z.a(c.this.q, "local_crash_lock", 10000L)) {
                List<CrashDetailBean> var1;
                if ((var1 = c.this.p.a()) != null && var1.size() > 0) {
                    com.tencent.bugly.proguard.x.c("Size of crash list: %s", var1.size());
                    List<CrashDetailBean> var2 = var1;
                    int var3;
                    if ((long)(var3 = var1.size()) > 20L) {
                        var2 = new ArrayList<>();
                        Collections.sort(var1);

                        for(int var4 = 0; (long)var4 < 20L; ++var4) {
                            var2.add(var1.get(var3 - 1 - var4));
                        }
                    }

                    c.this.p.a(var2, 0L, false, false, false);
                }

                com.tencent.bugly.proguard.z.b(c.this.q, "local_crash_lock");
            }
        }
    }

    public final void l() {
        this.t.checkUploadRecordCrash();
    }

    public final void m() {
        if (com.tencent.bugly.crashreport.common.info.a.b().d.equals(AppInfo.a(this.q))) {
            this.t.removeEmptyNativeRecordFiles();
        }

    }

    public final void a(int var1) {
        this.y = var1;
    }

    public final void a(boolean var1) {
        this.z = var1;
    }

    public final boolean n() {
        return this.z;
    }

    public final boolean o() {
        return (this.y & 16) > 0;
    }

    public final boolean p() {
        return (this.y & 8) > 0;
    }

    public final boolean q() {
        return (this.y & 4) > 0;
    }

    public final boolean r() {
        return (this.y & 2) > 0;
    }

    public final boolean s() {
        return (this.y & 1) > 0;
    }
}
